package com.application.lucky.adapter;

import android.app.Activity;
import android.widget.ImageView;

import com.application.lucky.R;
import com.application.lucky.bean.UserBean;
import com.application.lucky.config.Config;
import com.application.lucky.request.nav.UrlManager;
import com.qunar.im.ui.util.ProfileUtils;
import com.qunar.im.ui.view.recyclerview.BaseQuickAdapter;
import com.qunar.im.ui.view.recyclerview.BaseViewHolder;

public class AddFriendsAdapter extends BaseQuickAdapter<UserBean, BaseViewHolder> {

    public AddFriendsAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, UserBean item) {
        helper.setText(R.id.tv_item_new_friend_name, item.getShowName())
                .setText(R.id.tv_item_new_friend_message,item.getNickName())
                .setText(R.id.tv_item_new_friend_add, item.isAdd ? "已添加" : "添加")
                .setBackgroundRes(R.id.tv_item_new_friend_add, item.isAdd ? R.drawable.shape_button_bg_un : R.drawable.shape_button_bg)
                .addOnClickListener(R.id.tv_item_new_friend_add);
        ImageView view = helper.getView(R.id.iv_item_new_friend_thumb);
        ProfileUtils.displayGravatarRoundedCornerByImageSrc((Activity) mContext, UrlManager.getHeadPic(item.getHeadPic()), view);

    }


    public void upDataItemById(String id) {
        for (int i = 0; i < getData().size(); i++) {
            UserBean item = getItem(i);
            if (item != null) {
                if (id.equals(item.getUserId() + "")) {
                    item.isAdd = true;
                    notifyItemChanged(i);
                }
            }

        }

    }
}
